<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>新增人员--layui后台管理模板 2.0</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="../../css/public.css" media="all" />
</head>

<body class="childrenBody">
	<form class="layui-form" style="width:80%;">

		<input type="hidden" class="layui-input id" name="id">

		<div class="layui-col-md6 layui-col-xs12">
			<div class="layui-form-item">
				<label class="layui-form-label">姓名</label>
				<div class="layui-input-block">
					<input type="text" class="layui-input name" name="name" lay-verify="required" placeholder="请输入人员姓名">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">RFID</label>
				<div class="layui-input-block">
					<input type="text" class="layui-input rfid" name="rfid" lay-verify="required" placeholder="请输入RFID">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">联系方式</label>
				<div class="layui-input-block">
					<input type="text" class="layui-input phone" name="phone" lay-verify="phone" placeholder="请输入手机号">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">性别</label>
				<div class="layui-input-block sex">
					<input type="radio" name="sex" value="男" title="男" checked>
					<input type="radio" name="sex" value="女" title="女">
					<input type="radio" name="sex" value="保密" title="保密">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">机构</label>
				<div class="layui-input-block">
					<select name="dept" class="dept" lay-filter="dept">
						<option value="科室">科室</option>
						<option value="物流">物流</option>
					</select>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">职位</label>
				<div class="layui-input-block">
					<select name="duty" class="duty" lay-filter="duty">
						<option value="护士">护士</option>
						<option value="配送员">配送员</option>
					</select>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">简介</label>
				<div class="layui-input-block">
					<textarea placeholder="请输入用户简介" class="layui-textarea caption" name="caption"></textarea>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit="" lay-filter="addEmployee">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</div>
	</form>
	<script type="text/javascript" src="../../layui/layui.all.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>

	<script type="text/javascript">
		layui.use(['form', 'layer'], function () {
			var form = layui.form
			layer = parent.layer === undefined ? layui.layer : top.layer,
				$ = layui.jquery;

			form.on("submit(addEmployee)", function (data) {
				$.ajax({
					url: contextPath + '/sys/employee/save',
					type: 'post',
					dataType: 'json',
					data: data.field,
					beforeSend: function () {
						i = showLoad();
					},
					success: function (data) {
						closeLoad(i);

						if (data.code == 0) {
							layer.msg("人员信息保存成功！");
							layer.closeAll("iframe");
							//刷新父页面
							parent.location.reload();
						} else {
							layer.alert(data.msg);
						}
					},
					error: function (data) {
						closeLoad(i);
					}
				});
				return false;
			})

			//初始化数据,提供父窗口调用
			window.initData = function (edit) {

				//表单赋初值
				if (edit) {
					$(".id").val(edit.id);  //ID
					$(".name").val(edit.name);  //姓名
					$(".name").addClass("layui-disabled");//禁止修改姓名
					$(".rfid").val(edit.rfid);    //RFID
					$(".phone").val(edit.phone);    //联系方式
					$(".caption").text(edit.caption);    //用户说明
					$(".sex input[value=" + edit.sex + "]").prop("checked", "checked");  //性别
					$(".dept").val(edit.dept);  //机构
					$(".duty").val(edit.duty);  //职位
					form.render();
				}
			}
		})
	</script>
</body>

</html>